/*
 * @features: 功能
 * @description: 说明
 * @Date: 2021-09-19 00:17:58
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-09-19 19:43:11
 * @LastEditors: judu233
 */
import { readFileSync } from 'fs-extra';
import { join } from 'path';
import { createApp } from 'vue';
// import { ParsePSD } from './panel/paresPsd';
  
module.exports = Editor.Panel.define({
    listeners: {
        show() { console.log('show1f1'); },
        hide() { console.log('hide'); },
    },
    template: readFileSync(join(__dirname, '../../../../static/template/default/index.html'), 'utf-8'),
    style: readFileSync(join(__dirname, '../../../../static/style/default/index.css'), 'utf-8'),
    $: {
        app: '#app',
        text: '#text',
    },
    methods: {
        hello() {
            if (this.$.text) {
                this.$.text.innerHTML = 'hello';
                console.log('[cocos-panel-html.default]: hello');
            }
        },
    },
    ready() {
        if (this.$.text) {
            this.$.text.innerHTML = 'Hello Cocos.';
        }
        if (this.$.app) {
            const app = createApp({});
            app.component('my-counter', {
                template: readFileSync(join(__dirname, '../../../../static/template/vue/counter.html'), 'utf-8'),
                data() {
                    return {
                        counter: 0,
                    };
                }, methods: {
                    addition() {
                        this.counter += 1;
                    },
                    subtraction() {
                        this.counter -= 1;
                    },
                },
            });
            app.mount(this.$.app);
        }
        
        // this.$.app.addEventListener('confirm', () => {
        //     //TODO: 1.读取指定目录下的psd并转换到指定路径下。2.转换路径下已经有该预制体，只是把图替换
        //     let parsePsd = new ParsePSD();
        //     parsePsd.init();
        // });
    },
    beforeClose() { },
    close() { },
});
